package org.sproject.DrawRainbowTest;

import java.awt.Color;
import java.awt.Graphics;

import javax.swing.JPanel;

public class DrawRainbow extends JPanel {

	// define indigo and violet
	private final static Color VIOLET = new Color(123, 0, 128);
	private final static Color INDIGO = new Color(75, 0, 130);

	// colors to use in Rainbow, starting with the innermost
	// The two whtie entires result in an empty arc in the center
	private Color[] colors = { Color.WHITE, Color.WHITE, VIOLET, INDIGO,
			Color.BLUE, Color.GREEN, Color.YELLOW, Color.ORANGE, Color.RED };

	// constructor
	public DrawRainbow() {
		setBackground(Color.white); // set the background to white
	} // end Draw Rainbow constructor

	// draws a rainbow using concentric arcs
	public void paintComponent(Graphics g) {
		super.paintComponent(g);

		int radius = 20;// radius of an arc

		// draw the rianbow near the bottom-center
		int centerX = getWidth() / 2;
		int centerY = getHeight() - 10;

		// draws filled arcs starting witht eh outermost
		for (int counter = colors.length; counter > 0; counter--) {
			// set the color for the current arc
			g.setColor(colors[counter - 1]);

			// fill the arc from - to 180 degrees
			g.fillArc(centerX - counter * radius, centerY - counter * radius,
					counter * radius * 2, counter * radius * 2, 0, 180);
		} // end for
	} // end method paint component

} // end class DrawRainbow